const {email} = require('../config/config')
const nodemailer = require("nodemailer");

let transporter = nodemailer.createTransport({
    host: 'smtp.163.com',
    secureConnection: true, // use SSL
    port: 465,
    secure: true, // secure:true for port 465, secure:false for port 587
    auth: {
        user: email.user,
        pass: email.pass 
    }
});

// 注册方法
var register =  (email)=>{
    // 设置邮件内容（谁发送什么给谁）
let mailOptions = {
    from: 'linyixpy@163.com', // 发件人
    to: email, // 收件人
    subject: '欢迎你的注册', // 主题
    html: "<span>请点击<a href='localhost:3000'>链接</a>激活你的账号</span>", // html body
};
 
// 使用先前创建的传输器的 sendMail 方法传递消息对象
return new Promise((resolve, reject) => {
    transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
        console.log(err);
        reject(error) 
    }else{
        resolve('success')
    }
});
})

}
module.exports = {
    register
}
